package com.zzy.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzy.commonutils.R;
import com.zzy.edu.entity.EduCourse;
import com.zzy.edu.entity.EduTeacher;
import com.zzy.edu.service.EduCourseService;
import com.zzy.edu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.Map;

/**
 * @Author KAZU
 * @Date 2023/1/20 12:26
 * @Version 1.0
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {
	
	@Autowired
	private EduTeacherService teacherService;
	
	@Autowired
	private EduCourseService courseService;
	
	/**
	 * 分页查询讲师方法
	 * */
	@GetMapping("getTeacherFrontList/{page}/{limit}")
	public R getTeacherFrontList(@PathVariable Long page,
								 @PathVariable Long limit) {
		Page<EduTeacher> teacherPage = new Page<>(page, limit);
		Map<String, Object> map = teacherService.getTeacherFrontList(teacherPage);
		// 返回分页所有数据
		return R.ok().data(map);
	}
	
	/**
	 * 讲师详情功能
	 * */
	@GetMapping("getTeacherFrontInfo/{teacherId}")
	public R getTeacherFrontInfo(@PathVariable String teacherId) {
		// 根据讲师id查询讲师的基本信息
		EduTeacher eduTeacher = teacherService.getById(teacherId);
		// 根据讲师id查询所讲课程
		QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
		wrapper.eq("teacher_id", teacherId);
		List<EduCourse> courseList = courseService.list(wrapper);
		return R.ok().data("teacher", eduTeacher).data("courseList", courseList);
	}
	
	
	
	
}
